/*
 * MainFrame.java
 *
 * Created on 16 październik 2008, 22:30
 */
package JET.Frames;

import JET.Centers.Graphics.GraphicMode;
import JET.Centers.ControlCenter;
import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ComponentEvent;
import java.awt.event.KeyEvent;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JCheckBoxMenuItem;
import JET.*;
import JET.Centers.ControlCenterHelper;
import JET.Centers.Graphics.GUICenter.UtilTabs;
import JET.Exceptions.JETGraphicsException;
import JET.Exceptions.NotJETXMLProjectFileException;
import JET.Frames.AboutFrame.AboutDialog;
import JET.Frames.DataModels.DataModelsFactory;
import JET.Frames.advancedSimulationSettingsFrame.AdvancedSimulationSettingsDialog;
import JET.MouseStuff.*;
import JET.SA.SA_Dialogs;
import JET.SA.SA_Mass;
import JET.SA.SA_Menu;
import JET.SA.SA_SceneItems;
import JET.SA.SA_Selection;
import JET.SA.SA_Spring;
import JET.SA.SA_SpringBody;
import JET.SA.SA_Wall;
import JET.SwingUtils.TreeUtil;
import JET.UtilPanels.*;
import java.awt.event.ComponentListener;
import java.awt.event.MouseEvent;
import java.util.Formatter;
import java.util.Locale;
import JET.geom.Vec2d;
import JET.mygui.CenterTabsPane;
import JET.mygui.MultiSplitPane;
import JET.mygui.MyGuiHelper;
import JET.mygui.MyGuiManager;
import JET.mygui.UtilTabsPane;
import JET.physics.BodyFactory;
import JET.physics.Mass;
import JET.physics.Spring;
import JET.physics.bodies.SpringBody;
import JET.physics.Wall;
import JET.physics.bodies.RigidBody;
import XMLStuff.XMLHelper2;
import java.awt.BorderLayout;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.ArrayList;
import java.util.Collection;
import javax.swing.ImageIcon;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.xml.parsers.*;

import javax.xml.transform.*;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import org.w3c.dom.Document;
import org.xml.sax.SAXException;

/**
 *
 * @author  057Ry
 */
public class MainFrame extends javax.swing.JFrame implements Constants {

    private boolean debug = true;

    //private Animator animator;
    static final ControlCenter CC = ControlCenter.getInstance();
    private MultiSplitPane msp;
    
    public MainFrame() {
        initComponents();

        MyGuiManager.getInstance().setRootContainer(guiRootPanel);

        //initMSP();
        
        this.setViewScaleLabel(1.0);
        this.setGPWidthLabel(SCENE_START_WIDTH);
        this.setGPHeightLabel(SCENE_START_HEIGHT);
        this.addComponentListener(new MainFrameComponentListener());
    }

    public void initMSP() {
//        // Create GUI hierarchy by hand ...
//        msp = new MultiSplitPane(1, true);
//        CenterTabsPane ctp = new CenterTabsPane("This is the one!");
//        ctp.add(CC.GUIC.getGraphicPanelContainer());
//        msp.setCellComponent(0, ctp, true);
//        guiRootPanel.add(msp, BorderLayout.CENTER);
//        initUtils();

//        // Create GUI hierarchy by saved xml state ...
//        msp = CC.GUIC.builGuiSctructure("aTestMSP.xml", CC);
//        guiRootPanel.add(msp, BorderLayout.CENTER);

    }
    public void initUtils() {
//        MultiSplitPane mspV = new MultiSplitPane(3, false);
//
//            UtilTabsPane utp = new UtilTabsPane("Util Tabs Pane");
//            utp.add( (Component) CC.GUIC.getUtilTab(UtilTabs.Tools));
//        mspV.setCellComponent(0, utp, true);
//
//            utp = new UtilTabsPane("Util Tabs Pane");
//            utp.add( (Component) CC.GUIC.getUtilTab(UtilTabs.Bodies));
//        mspV.setCellComponent(1, utp, true);
//
//            utp = new UtilTabsPane("Util Tabs Pane");
//            utp.add( MyGuiHelper.getNewJScrollPane( (Component) CC.GUIC.getUtilTab(UtilTabs.Mass)));
//            utp.add( MyGuiHelper.getNewJScrollPane( (Component) CC.GUIC.getUtilTab(UtilTabs.Spring)));
//            utp.add( MyGuiHelper.getNewJScrollPane( (Component) CC.GUIC.getUtilTab(UtilTabs.RSpring)));
//            utp.add( MyGuiHelper.getNewJScrollPane( (Component) CC.GUIC.getUtilTab(UtilTabs.ToolsOptions)));
//            utp.add( MyGuiHelper.getNewJScrollPane( (Component) CC.GUIC.getUtilTab(UtilTabs.SpringBody)));
//            utp.add( MyGuiHelper.getNewJScrollPane( (Component) CC.GUIC.getUtilTab(UtilTabs.Torque)));
//            utp.add( (Component) CC.GUIC.getUtilTab(UtilTabs.Scripts));
//            utp.add( (Component) CC.GUIC.getUtilTab(UtilTabs.Output));
//            utp.add( (Component) CC.GUIC.getUtilTab(UtilTabs.SceneInspector));
//
//        mspV.setCellComponent(2, utp, true);
//
//        msp.insert(mspV, false, 0, 150);
    }

    public void setRecordButtonEnabled(boolean e) {
        recordButton.setEnabled(e);
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        popUpMenuSpringBody = new javax.swing.JPopupMenu();
        menuTransform = new javax.swing.JMenu();
        menuItemTransformScale = new javax.swing.JMenuItem();
        menuItemTransformMove = new javax.swing.JMenuItem();
        menuItemTransformRotate = new javax.swing.JMenuItem();
        jSeparator4 = new javax.swing.JSeparator();
        menuItemTransformRotate30 = new javax.swing.JMenuItem();
        menuItemTransformRotate45 = new javax.swing.JMenuItem();
        menuItemTransformRotate90 = new javax.swing.JMenuItem();
        menuItemTransformRotate180 = new javax.swing.JMenuItem();
        jSeparator3 = new javax.swing.JSeparator();
        menuItemTranformFlipX = new javax.swing.JMenuItem();
        menuItemTransformFlipY = new javax.swing.JMenuItem();
        menuItemCopy = new javax.swing.JMenuItem();
        menuSelect = new javax.swing.JMenu();
        menuItemSelectAll = new javax.swing.JMenuItem();
        menuItemSelectMasses = new javax.swing.JMenuItem();
        menuItemSelectSprings = new javax.swing.JMenuItem();
        menuItemSelectWalls = new javax.swing.JMenuItem();
        jSeparator2 = new javax.swing.JSeparator();
        menuMasses = new javax.swing.JMenu();
        menuItemMassesSetMassValue = new javax.swing.JMenuItem();
        menuItemMassesSetVelocity = new javax.swing.JMenuItem();
        menuSprings = new javax.swing.JMenu();
        menuItemSpringsRecalculateStartLength = new javax.swing.JMenuItem();
        menuItemSpringsSetKs = new javax.swing.JMenuItem();
        menuItemSpringsSetKd = new javax.swing.JMenuItem();
        menuItemSpringsSetStartLength = new javax.swing.JMenuItem();
        popUpMenuScene = new javax.swing.JPopupMenu();
        menuSelection = new javax.swing.JMenu();
        menuItemSpreadSelection = new javax.swing.JMenuItem();
        menuItemGroupAsSceneItem = new javax.swing.JMenuItem();
        statusBarPanel = new javax.swing.JPanel();
        panelMouseScreenPos = new javax.swing.JPanel();
        labelMouseScreenPos = new javax.swing.JLabel();
        panelMouseEnginePos = new javax.swing.JPanel();
        labelMouseEnginePos = new javax.swing.JLabel();
        panelViewScale = new javax.swing.JPanel();
        labelViewScale = new javax.swing.JLabel();
        panelMouseMode = new javax.swing.JPanel();
        labelMouseMode = new javax.swing.JLabel();
        panelMouseTask = new javax.swing.JPanel();
        labelMouseTask = new javax.swing.JLabel();
        guiRootPanel = new javax.swing.JPanel();
        jPanel1 = new javax.swing.JPanel();
        drawForcesToggleButton = new javax.swing.JToggleButton();
        drawVelocitiesToggleButton = new javax.swing.JToggleButton();
        newProjectButton = new javax.swing.JButton();
        openProjectButton = new javax.swing.JButton();
        startButton = new javax.swing.JButton();
        saveProjectButton = new javax.swing.JButton();
        stopButton = new javax.swing.JButton();
        refreshButton = new javax.swing.JButton();
        followCameraToggleButton = new javax.swing.JToggleButton();
        gravityTextField = new javax.swing.JTextField();
        recordButton = new javax.swing.JToggleButton();
        timestepSlider = new javax.swing.JSlider();
        timestepTextField = new javax.swing.JTextField();
        gravityToggleButton = new javax.swing.JToggleButton();
        dampingToggleButton = new javax.swing.JToggleButton();
        jPanel2 = new javax.swing.JPanel();
        mainGridToggleButton = new javax.swing.JToggleButton();
        helpGridToggleButton = new javax.swing.JToggleButton();
        jButton7 = new javax.swing.JButton();
        findCollisionsToggleButton = new javax.swing.JToggleButton();
        jButton1 = new javax.swing.JButton();
        actionFrameToggleButton = new javax.swing.JToggleButton();
        solveCollisionsToggleButton = new javax.swing.JToggleButton();
        jButton6 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jButton8 = new javax.swing.JButton();
        glToggleButton = new javax.swing.JToggleButton();
        jButton9 = new javax.swing.JButton();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        jMenuItem5 = new javax.swing.JMenuItem();
        jSeparator1 = new javax.swing.JSeparator();
        jMenuItem3 = new javax.swing.JMenuItem();
        jMenuItem2 = new javax.swing.JMenuItem();
        jMenuItem4 = new javax.swing.JMenuItem();
        jMenu2 = new javax.swing.JMenu();
        jMenu4 = new javax.swing.JMenu();
        showMaterialsDialogCheckBoxMenuItem = new javax.swing.JCheckBoxMenuItem();
        showActionsDialogCheckBoxMenuItem = new javax.swing.JCheckBoxMenuItem();
        showKeyboardDialogCheckBoxMenuItem = new javax.swing.JCheckBoxMenuItem();
        showRecorderDialogCheckBoxMenuItem = new javax.swing.JCheckBoxMenuItem();
        jSeparator6 = new javax.swing.JPopupMenu.Separator();
        saveGuiLayoutMenuItem = new javax.swing.JMenuItem();
        resetGuiLayoutMenuItem = new javax.swing.JMenuItem();
        jMenu3 = new javax.swing.JMenu();
        jMenuItem1 = new javax.swing.JMenuItem();
        jMenuItem6 = new javax.swing.JMenuItem();
        jMenu5 = new javax.swing.JMenu();
        jMenuItem7 = new javax.swing.JMenuItem();
        jSeparator5 = new javax.swing.JPopupMenu.Separator();
        jMenuItem8 = new javax.swing.JMenuItem();

        menuTransform.setText("Transform");

        menuItemTransformScale.setText("Scale");
        menuItemTransformScale.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuItemTransformScaleActionPerformed(evt);
            }
        });
        menuTransform.add(menuItemTransformScale);

        menuItemTransformMove.setText("Move");
        menuItemTransformMove.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuItemTransformMoveActionPerformed(evt);
            }
        });
        menuTransform.add(menuItemTransformMove);

        menuItemTransformRotate.setText("Rotate");
        menuItemTransformRotate.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuItemTransformRotateActionPerformed(evt);
            }
        });
        menuTransform.add(menuItemTransformRotate);
        menuTransform.add(jSeparator4);

        menuItemTransformRotate30.setText("Rotate by 30º");
        menuItemTransformRotate30.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuItemTransformRotate30ActionPerformed(evt);
            }
        });
        menuTransform.add(menuItemTransformRotate30);

        menuItemTransformRotate45.setText("Rotate by 45º");
        menuItemTransformRotate45.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuItemTransformRotate45ActionPerformed(evt);
            }
        });
        menuTransform.add(menuItemTransformRotate45);

        menuItemTransformRotate90.setText("Rotate by 90º");
        menuItemTransformRotate90.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuItemTransformRotate90ActionPerformed(evt);
            }
        });
        menuTransform.add(menuItemTransformRotate90);

        menuItemTransformRotate180.setText("Rotate by 180º");
        menuItemTransformRotate180.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuItemTransformRotate180ActionPerformed(evt);
            }
        });
        menuTransform.add(menuItemTransformRotate180);
        menuTransform.add(jSeparator3);

        menuItemTranformFlipX.setText("Flip horizontally");
        menuItemTranformFlipX.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuItemTranformFlipXActionPerformed(evt);
            }
        });
        menuTransform.add(menuItemTranformFlipX);

        menuItemTransformFlipY.setText("Flip Vertically");
        menuItemTransformFlipY.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuItemTransformFlipYActionPerformed(evt);
            }
        });
        menuTransform.add(menuItemTransformFlipY);

        popUpMenuSpringBody.add(menuTransform);

        menuItemCopy.setText("Copy");
        menuItemCopy.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuItemCopyActionPerformed(evt);
            }
        });
        popUpMenuSpringBody.add(menuItemCopy);

        menuSelect.setText("Select");

        menuItemSelectAll.setText("All");
        menuItemSelectAll.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuItemSelectAllActionPerformed(evt);
            }
        });
        menuSelect.add(menuItemSelectAll);

        menuItemSelectMasses.setText("Masses");
        menuItemSelectMasses.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuItemSelectMassesActionPerformed(evt);
            }
        });
        menuSelect.add(menuItemSelectMasses);

        menuItemSelectSprings.setText("Springs");
        menuItemSelectSprings.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuItemSelectSpringsActionPerformed(evt);
            }
        });
        menuSelect.add(menuItemSelectSprings);

        menuItemSelectWalls.setText("Walls");
        menuItemSelectWalls.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuItemSelectWallsActionPerformed(evt);
            }
        });
        menuSelect.add(menuItemSelectWalls);

        popUpMenuSpringBody.add(menuSelect);
        popUpMenuSpringBody.add(jSeparator2);

        menuMasses.setText("Masses");

        menuItemMassesSetMassValue.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuItemMassesSetMassValueActionPerformed(evt);
            }
        });
        menuMasses.add(menuItemMassesSetMassValue);

        menuItemMassesSetVelocity.setText("Set Velocity");
        menuItemMassesSetVelocity.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuItemMassesSetVelocityActionPerformed(evt);
            }
        });
        menuMasses.add(menuItemMassesSetVelocity);

        popUpMenuSpringBody.add(menuMasses);

        menuSprings.setText("Springs");

        menuItemSpringsRecalculateStartLength.setText("Recalculate start length");
        menuItemSpringsRecalculateStartLength.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuItemSpringsRecalculateStartLengthActionPerformed(evt);
            }
        });
        menuSprings.add(menuItemSpringsRecalculateStartLength);

        menuItemSpringsSetKs.setText("Set ks");
        menuItemSpringsSetKs.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuItemSpringsSetKsActionPerformed(evt);
            }
        });
        menuSprings.add(menuItemSpringsSetKs);

        menuItemSpringsSetKd.setText("Set kd");
        menuItemSpringsSetKd.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuItemSpringsSetKdActionPerformed(evt);
            }
        });
        menuSprings.add(menuItemSpringsSetKd);

        menuItemSpringsSetStartLength.setText("Set Start Length");
        menuItemSpringsSetStartLength.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuItemSpringsSetStartLengthActionPerformed(evt);
            }
        });
        menuSprings.add(menuItemSpringsSetStartLength);

        popUpMenuSpringBody.add(menuSprings);

        menuSelection.setText("Selection");

        menuItemSpreadSelection.setText("Spread");
        menuItemSpreadSelection.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuItemSpreadSelectionActionPerformed(evt);
            }
        });
        menuSelection.add(menuItemSpreadSelection);

        menuItemGroupAsSceneItem.setText("Group as scene item");
        menuItemGroupAsSceneItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuItemGroupAsSceneItemActionPerformed(evt);
            }
        });
        menuSelection.add(menuItemGroupAsSceneItem);

        popUpMenuScene.add(menuSelection);

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle(Constants.MAIN_FRAME_TITLE);

        statusBarPanel.setFocusable(false);

        panelMouseScreenPos.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));
        panelMouseScreenPos.setToolTipText("mouse position on screen");

        labelMouseScreenPos.setText("screen: 0000;0000");

        javax.swing.GroupLayout panelMouseScreenPosLayout = new javax.swing.GroupLayout(panelMouseScreenPos);
        panelMouseScreenPos.setLayout(panelMouseScreenPosLayout);
        panelMouseScreenPosLayout.setHorizontalGroup(
            panelMouseScreenPosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(labelMouseScreenPos, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 116, Short.MAX_VALUE)
        );
        panelMouseScreenPosLayout.setVerticalGroup(
            panelMouseScreenPosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(labelMouseScreenPos)
        );

        panelMouseEnginePos.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));
        panelMouseEnginePos.setToolTipText("mouse position in scene");

        labelMouseEnginePos.setText("scene: 0000;0000");
        labelMouseEnginePos.setToolTipText("mouse position in simulation scene");

        javax.swing.GroupLayout panelMouseEnginePosLayout = new javax.swing.GroupLayout(panelMouseEnginePos);
        panelMouseEnginePos.setLayout(panelMouseEnginePosLayout);
        panelMouseEnginePosLayout.setHorizontalGroup(
            panelMouseEnginePosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(labelMouseEnginePos, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 116, Short.MAX_VALUE)
        );
        panelMouseEnginePosLayout.setVerticalGroup(
            panelMouseEnginePosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(labelMouseEnginePos)
        );

        panelViewScale.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));
        panelViewScale.setToolTipText("mouse position in scene");

        labelViewScale.setText("view scale: 1.00");
        labelViewScale.setToolTipText("mouse position in simulation scene");

        javax.swing.GroupLayout panelViewScaleLayout = new javax.swing.GroupLayout(panelViewScale);
        panelViewScale.setLayout(panelViewScaleLayout);
        panelViewScaleLayout.setHorizontalGroup(
            panelViewScaleLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(labelViewScale, javax.swing.GroupLayout.DEFAULT_SIZE, 115, Short.MAX_VALUE)
        );
        panelViewScaleLayout.setVerticalGroup(
            panelViewScaleLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(labelViewScale)
        );

        panelMouseMode.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));
        panelMouseMode.setToolTipText("mouse position in scene");

        labelMouseMode.setText("mouse mode:");
        labelMouseMode.setToolTipText("mouse position in simulation scene");

        javax.swing.GroupLayout panelMouseModeLayout = new javax.swing.GroupLayout(panelMouseMode);
        panelMouseMode.setLayout(panelMouseModeLayout);
        panelMouseModeLayout.setHorizontalGroup(
            panelMouseModeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(labelMouseMode, javax.swing.GroupLayout.DEFAULT_SIZE, 187, Short.MAX_VALUE)
        );
        panelMouseModeLayout.setVerticalGroup(
            panelMouseModeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(labelMouseMode)
        );

        panelMouseTask.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));
        panelMouseTask.setToolTipText("mouse position in scene");

        labelMouseTask.setText("mouse task:");
        labelMouseTask.setToolTipText("mouse position in simulation scene");

        javax.swing.GroupLayout panelMouseTaskLayout = new javax.swing.GroupLayout(panelMouseTask);
        panelMouseTask.setLayout(panelMouseTaskLayout);
        panelMouseTaskLayout.setHorizontalGroup(
            panelMouseTaskLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(labelMouseTask, javax.swing.GroupLayout.DEFAULT_SIZE, 187, Short.MAX_VALUE)
        );
        panelMouseTaskLayout.setVerticalGroup(
            panelMouseTaskLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(labelMouseTask)
        );

        javax.swing.GroupLayout statusBarPanelLayout = new javax.swing.GroupLayout(statusBarPanel);
        statusBarPanel.setLayout(statusBarPanelLayout);
        statusBarPanelLayout.setHorizontalGroup(
            statusBarPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(statusBarPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(panelMouseScreenPos, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(panelMouseEnginePos, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(panelViewScale, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(panelMouseMode, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(panelMouseTask, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(436, Short.MAX_VALUE))
        );
        statusBarPanelLayout.setVerticalGroup(
            statusBarPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(panelViewScale, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(panelMouseEnginePos, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(panelMouseScreenPos, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(panelMouseMode, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(panelMouseTask, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        guiRootPanel.setLayout(new java.awt.BorderLayout());

        jPanel1.setAlignmentX(0.0F);
        jPanel1.setAlignmentY(0.0F);
        jPanel1.setMinimumSize(new java.awt.Dimension(600, 10));
        jPanel1.setOpaque(false);
        jPanel1.setPreferredSize(new java.awt.Dimension(700, 28));

        drawForcesToggleButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/JET/Images/force.PNG"))); // NOI18N
        drawForcesToggleButton.setToolTipText("draw forces");
        drawForcesToggleButton.setAlignmentY(0.0F);
        drawForcesToggleButton.setFocusable(false);
        drawForcesToggleButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        drawForcesToggleButton.setMaximumSize(new java.awt.Dimension(28, 28));
        drawForcesToggleButton.setMinimumSize(new java.awt.Dimension(20, 20));
        drawForcesToggleButton.setPreferredSize(new java.awt.Dimension(28, 28));
        drawForcesToggleButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                drawForcesToggleButtonActionPerformed(evt);
            }
        });

        drawVelocitiesToggleButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/JET/Images/velocity.PNG"))); // NOI18N
        drawVelocitiesToggleButton.setToolTipText("draw velocities");
        drawVelocitiesToggleButton.setAlignmentY(0.0F);
        drawVelocitiesToggleButton.setFocusable(false);
        drawVelocitiesToggleButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        drawVelocitiesToggleButton.setMaximumSize(new java.awt.Dimension(28, 28));
        drawVelocitiesToggleButton.setMinimumSize(new java.awt.Dimension(20, 20));
        drawVelocitiesToggleButton.setPreferredSize(new java.awt.Dimension(28, 28));
        drawVelocitiesToggleButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                drawVelocitiesToggleButtonActionPerformed(evt);
            }
        });

        newProjectButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/JET/Images/New Project 22x22.png"))); // NOI18N
        newProjectButton.setToolTipText("New Project");
        newProjectButton.setAlignmentY(0.0F);
        newProjectButton.setFocusable(false);
        newProjectButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        newProjectButton.setMaximumSize(new java.awt.Dimension(28, 28));
        newProjectButton.setMinimumSize(new java.awt.Dimension(20, 20));
        newProjectButton.setPreferredSize(new java.awt.Dimension(28, 28));
        newProjectButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                newProjectButtonActionPerformed(evt);
            }
        });

        openProjectButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/JET/Images/Open Project 22x22.png"))); // NOI18N
        openProjectButton.setToolTipText("Open project (Ctrl+O)");
        openProjectButton.setAlignmentY(0.0F);
        openProjectButton.setFocusable(false);
        openProjectButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        openProjectButton.setMaximumSize(new java.awt.Dimension(28, 28));
        openProjectButton.setMinimumSize(new java.awt.Dimension(20, 20));
        openProjectButton.setPreferredSize(new java.awt.Dimension(28, 28));
        openProjectButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                openProjectButtonActionPerformed(evt);
            }
        });

        startButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/JET/Images/start_animation.PNG"))); // NOI18N
        startButton.setToolTipText("start simulation");
        startButton.setAlignmentY(0.0F);
        startButton.setFocusable(false);
        startButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        startButton.setMaximumSize(new java.awt.Dimension(28, 28));
        startButton.setMinimumSize(new java.awt.Dimension(20, 20));
        startButton.setPreferredSize(new java.awt.Dimension(28, 28));
        startButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                startButtonActionPerformed(evt);
            }
        });

        saveProjectButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/JET/Images/Save Project 22x22.png"))); // NOI18N
        saveProjectButton.setToolTipText("Save Project (Ctrl+S)");
        saveProjectButton.setAlignmentY(0.0F);
        saveProjectButton.setFocusable(false);
        saveProjectButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        saveProjectButton.setMaximumSize(new java.awt.Dimension(28, 28));
        saveProjectButton.setMinimumSize(new java.awt.Dimension(20, 20));
        saveProjectButton.setPreferredSize(new java.awt.Dimension(28, 28));
        saveProjectButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                saveProjectButtonActionPerformed(evt);
            }
        });

        stopButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/JET/Images/stop_animation.PNG"))); // NOI18N
        stopButton.setToolTipText("stop simulation");
        stopButton.setAlignmentY(0.0F);
        stopButton.setFocusable(false);
        stopButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        stopButton.setMaximumSize(new java.awt.Dimension(28, 28));
        stopButton.setMinimumSize(new java.awt.Dimension(20, 20));
        stopButton.setPreferredSize(new java.awt.Dimension(28, 28));
        stopButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                stopButtonActionPerformed(evt);
            }
        });

        refreshButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/JET/Images/Refresh 22x22.png"))); // NOI18N
        refreshButton.setToolTipText("Refresh Project");
        refreshButton.setAlignmentY(0.0F);
        refreshButton.setEnabled(false);
        refreshButton.setFocusable(false);
        refreshButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        refreshButton.setMaximumSize(new java.awt.Dimension(28, 28));
        refreshButton.setMinimumSize(new java.awt.Dimension(20, 20));
        refreshButton.setPreferredSize(new java.awt.Dimension(28, 28));
        refreshButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                refreshButtonActionPerformed(evt);
            }
        });

        followCameraToggleButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/JET/Images/follow_camera.PNG"))); // NOI18N
        followCameraToggleButton.setToolTipText("turn follow camera ON/OFF");
        followCameraToggleButton.setAlignmentY(0.0F);
        followCameraToggleButton.setFocusable(false);
        followCameraToggleButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        followCameraToggleButton.setMaximumSize(new java.awt.Dimension(28, 28));
        followCameraToggleButton.setMinimumSize(new java.awt.Dimension(20, 20));
        followCameraToggleButton.setPreferredSize(new java.awt.Dimension(28, 28));
        followCameraToggleButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                followCameraToggleButtonActionPerformed(evt);
            }
        });

        gravityTextField.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        gravityTextField.setText(CC.getCurrentScene()!=null?""+CC.getCurrentScene().getJETContext().gravity:"");
        gravityTextField.setAlignmentX(0.0F);
        gravityTextField.setAlignmentY(0.0F);
        gravityTextField.setAutoscrolls(false);
        gravityTextField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                gravityTextFieldActionPerformed(evt);
            }
        });

        recordButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/JET/Images/record.PNG"))); // NOI18N
        recordButton.setSelected(CC.isRecord());
        recordButton.setToolTipText("record");
        recordButton.setAlignmentY(0.0F);
        recordButton.setEnabled(false);
        recordButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        recordButton.setMaximumSize(new java.awt.Dimension(28, 28));
        recordButton.setMinimumSize(null);
        recordButton.setPreferredSize(new java.awt.Dimension(28, 28));
        recordButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                recordButtonActionPerformed(evt);
            }
        });

        timestepSlider.setMaximum(20);
        timestepSlider.setToolTipText("simulation time step");
        timestepSlider.setValue(8);
        timestepSlider.setAlignmentX(0.0F);
        timestepSlider.setAlignmentY(0.0F);
        timestepSlider.setFocusable(false);
        timestepSlider.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                timestepSliderStateChanged(evt);
            }
        });

        timestepTextField.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        timestepTextField.setText("0.08");
        timestepTextField.setAlignmentX(0.0F);
        timestepTextField.setAlignmentY(0.0F);
        timestepTextField.setAutoscrolls(false);
        timestepTextField.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                timestepTextFieldKeyPressed(evt);
            }
        });

        gravityToggleButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/JET/Images/gravity.PNG"))); // NOI18N
        gravityToggleButton.setToolTipText("gravity");
        gravityToggleButton.setAlignmentY(0.0F);
        gravityToggleButton.setFocusable(false);
        gravityToggleButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        gravityToggleButton.setMaximumSize(new java.awt.Dimension(28, 28));
        gravityToggleButton.setMinimumSize(new java.awt.Dimension(20, 20));
        gravityToggleButton.setPreferredSize(new java.awt.Dimension(28, 28));
        gravityToggleButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                gravityToggleButtonActionPerformed(evt);
            }
        });

        dampingToggleButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/JET/Images/damping.PNG"))); // NOI18N
        dampingToggleButton.setToolTipText("damping");
        dampingToggleButton.setAlignmentY(0.0F);
        dampingToggleButton.setFocusable(false);
        dampingToggleButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        dampingToggleButton.setMaximumSize(new java.awt.Dimension(28, 28));
        dampingToggleButton.setMinimumSize(new java.awt.Dimension(20, 20));
        dampingToggleButton.setPreferredSize(new java.awt.Dimension(28, 28));
        dampingToggleButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                dampingToggleButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addComponent(newProjectButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(5, 5, 5)
                .addComponent(openProjectButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(refreshButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(saveProjectButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(startButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(stopButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(recordButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(timestepSlider, javax.swing.GroupLayout.PREFERRED_SIZE, 128, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(timestepTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(16, 16, 16)
                .addComponent(gravityToggleButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(gravityTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(dampingToggleButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(drawForcesToggleButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(drawVelocitiesToggleButton, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(followCameraToggleButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(39, 39, 39))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                .addComponent(saveProjectButton, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(refreshButton, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addComponent(newProjectButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addComponent(openProjectButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addComponent(startButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addComponent(stopButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addComponent(recordButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                .addComponent(timestepTextField, javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(timestepSlider, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addComponent(gravityToggleButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addComponent(drawForcesToggleButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(drawVelocitiesToggleButton, javax.swing.GroupLayout.DEFAULT_SIZE, 28, Short.MAX_VALUE)
                        .addComponent(followCameraToggleButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(dampingToggleButton, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(gravityTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 28, Short.MAX_VALUE)
                .addContainerGap())
        );

        jPanel2.setAlignmentX(0.0F);
        jPanel2.setMinimumSize(new java.awt.Dimension(100, 10));
        jPanel2.setPreferredSize(new java.awt.Dimension(431, 28));

        mainGridToggleButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/JET/Images/main_grid.PNG"))); // NOI18N
        mainGridToggleButton.setSelected(true);
        mainGridToggleButton.setToolTipText("main grid");
        mainGridToggleButton.setFocusable(false);
        mainGridToggleButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        mainGridToggleButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mainGridToggleButtonActionPerformed(evt);
            }
        });

        helpGridToggleButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/JET/Images/help_grid.PNG"))); // NOI18N
        helpGridToggleButton.setSelected(true);
        helpGridToggleButton.setToolTipText("help grid");
        helpGridToggleButton.setFocusable(false);
        helpGridToggleButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        helpGridToggleButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                helpGridToggleButtonActionPerformed(evt);
            }
        });

        jButton7.setIcon(new javax.swing.ImageIcon(getClass().getResource("/JET/Images/red_cross.PNG"))); // NOI18N
        jButton7.setToolTipText("delete actual spring body");
        jButton7.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton7ActionPerformed(evt);
            }
        });

        findCollisionsToggleButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/JET/Images/collision_detection.PNG"))); // NOI18N
        findCollisionsToggleButton.setSelected(true);
        findCollisionsToggleButton.setToolTipText("collision detection");
        findCollisionsToggleButton.setFocusable(false);
        findCollisionsToggleButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        findCollisionsToggleButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                findCollisionsToggleButtonActionPerformed(evt);
            }
        });

        jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/JET/Images/clear_scene.PNG"))); // NOI18N
        jButton1.setToolTipText("clear scene");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        actionFrameToggleButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/JET/Images/action_frame.PNG"))); // NOI18N
        actionFrameToggleButton.setSelected(true);
        actionFrameToggleButton.setToolTipText("draw action frame aroud actual spring body");
        actionFrameToggleButton.setFocusable(false);
        actionFrameToggleButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        actionFrameToggleButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                actionFrameToggleButtonActionPerformed(evt);
            }
        });

        solveCollisionsToggleButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/JET/Images/collision_answer.PNG"))); // NOI18N
        solveCollisionsToggleButton.setSelected(true);
        solveCollisionsToggleButton.setToolTipText("answering collisions");
        solveCollisionsToggleButton.setFocusable(false);
        solveCollisionsToggleButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        solveCollisionsToggleButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                solveCollisionsToggleButtonActionPerformed(evt);
            }
        });

        jButton6.setIcon(new javax.swing.ImageIcon(getClass().getResource("/JET/Images/green_plus.PNG"))); // NOI18N
        jButton6.setToolTipText("new spring body");
        jButton6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton6ActionPerformed(evt);
            }
        });

        jButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/JET/Images/zero_velocities.PNG"))); // NOI18N
        jButton2.setToolTipText("zero mass velocity");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jButton3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/JET/Images/random_velocities.PNG"))); // NOI18N
        jButton3.setToolTipText("random velocities");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        jButton8.setToolTipText("this is test button - dont uese it :P");
        jButton8.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton8ActionPerformed(evt);
            }
        });

        glToggleButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/JET/Images/opengl_icon.png"))); // NOI18N
        glToggleButton.setToolTipText("main grid");
        glToggleButton.setFocusable(false);
        glToggleButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        glToggleButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                glToggleButtonActionPerformed(evt);
            }
        });

        jButton9.setToolTipText("this is test button - dont uese it :P");
        jButton9.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton9ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addComponent(glToggleButton, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(mainGridToggleButton, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(helpGridToggleButton, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(actionFrameToggleButton, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(27, 27, 27)
                .addComponent(findCollisionsToggleButton, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(solveCollisionsToggleButton, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jButton8, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton9, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 20, Short.MAX_VALUE)
                .addComponent(jButton6, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton7, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(solveCollisionsToggleButton, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(helpGridToggleButton, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(mainGridToggleButton, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(findCollisionsToggleButton, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(glToggleButton, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton8, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(actionFrameToggleButton, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton7, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton6, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton9, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        jMenuBar1.setFocusable(false);

        jMenu1.setText("File");

        jMenuItem5.setText("New Project");
        jMenuItem5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem5ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem5);
        jMenu1.add(jSeparator1);

        jMenuItem3.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_O, java.awt.event.InputEvent.CTRL_MASK));
        jMenuItem3.setText("Open");
        jMenuItem3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem3ActionPerformed1(evt);
            }
        });
        jMenu1.add(jMenuItem3);

        jMenuItem2.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_S, java.awt.event.InputEvent.CTRL_MASK));
        jMenuItem2.setText("Save");
        jMenuItem2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem2ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem2);

        jMenuItem4.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_S, java.awt.event.InputEvent.ALT_MASK | java.awt.event.InputEvent.CTRL_MASK));
        jMenuItem4.setText("Save As");
        jMenuItem4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem4ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem4);

        jMenuBar1.add(jMenu1);

        jMenu2.setText("Edit");
        jMenuBar1.add(jMenu2);

        jMenu4.setText("Windows");

        showMaterialsDialogCheckBoxMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_M, java.awt.event.InputEvent.ALT_MASK));
        showMaterialsDialogCheckBoxMenuItem.setText("Show Materials dialog");
        showMaterialsDialogCheckBoxMenuItem.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                showMaterialsDialogCheckBoxMenuItemItemStateChanged(evt);
            }
        });
        jMenu4.add(showMaterialsDialogCheckBoxMenuItem);

        showActionsDialogCheckBoxMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_A, java.awt.event.InputEvent.ALT_MASK));
        showActionsDialogCheckBoxMenuItem.setText("Show Actions dialog");
        showActionsDialogCheckBoxMenuItem.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                showActionsDialogCheckBoxMenuItemItemStateChanged(evt);
            }
        });
        jMenu4.add(showActionsDialogCheckBoxMenuItem);

        showKeyboardDialogCheckBoxMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_K, java.awt.event.InputEvent.ALT_MASK));
        showKeyboardDialogCheckBoxMenuItem.setText("Show Keyboard dialog");
        showKeyboardDialogCheckBoxMenuItem.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                showKeyboardDialogCheckBoxMenuItemItemStateChanged(evt);
            }
        });
        jMenu4.add(showKeyboardDialogCheckBoxMenuItem);

        showRecorderDialogCheckBoxMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_R, java.awt.event.InputEvent.ALT_MASK));
        showRecorderDialogCheckBoxMenuItem.setText("Show Recorder dialog");
        showRecorderDialogCheckBoxMenuItem.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                showRecorderDialogCheckBoxMenuItemItemStateChanged(evt);
            }
        });
        jMenu4.add(showRecorderDialogCheckBoxMenuItem);
        jMenu4.add(jSeparator6);

        saveGuiLayoutMenuItem.setText("Save gui layout");
        saveGuiLayoutMenuItem.setActionCommand("Save GUI layout");
        saveGuiLayoutMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                saveGuiLayoutMenuItemActionPerformed(evt);
            }
        });
        jMenu4.add(saveGuiLayoutMenuItem);

        resetGuiLayoutMenuItem.setText("Reset gui layout");
        resetGuiLayoutMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                resetGuiLayoutMenuItemActionPerformed(evt);
            }
        });
        jMenu4.add(resetGuiLayoutMenuItem);

        jMenuBar1.add(jMenu4);

        jMenu3.setText("Settings");
        jMenu3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenu3ActionPerformed(evt);
            }
        });

        jMenuItem1.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_D, java.awt.event.InputEvent.ALT_MASK | java.awt.event.InputEvent.CTRL_MASK));
        jMenuItem1.setText("Display/Draw options");
        jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem1ActionPerformed(evt);
            }
        });
        jMenu3.add(jMenuItem1);

        jMenuItem6.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_A, java.awt.event.InputEvent.ALT_MASK | java.awt.event.InputEvent.CTRL_MASK));
        jMenuItem6.setText("Advanced settings");
        jMenuItem6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem6ActionPerformed(evt);
            }
        });
        jMenu3.add(jMenuItem6);

        jMenuBar1.add(jMenu3);

        jMenu5.setText("Help");

        jMenuItem7.setText("This is beta, no help avaiable ;)");
        jMenuItem7.setToolTipText("sorry for this, but what to say - that's just raw truth ! ;)");
        jMenuItem7.setEnabled(false);
        jMenuItem7.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem7ActionPerformed(evt);
            }
        });
        jMenu5.add(jMenuItem7);
        jMenu5.add(jSeparator5);

        jMenuItem8.setText("About");
        jMenuItem8.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem8ActionPerformed(evt);
            }
        });
        jMenu5.add(jMenuItem8);

        jMenuBar1.add(jMenu5);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(statusBarPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(71, Short.MAX_VALUE))
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 644, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, 497, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(135, Short.MAX_VALUE))
            .addComponent(guiRootPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 1282, Short.MAX_VALUE)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGap(0, 1282, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(guiRootPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 730, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(statusBarPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGap(0, 788, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void startButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_startButtonActionPerformed

        if (CC.isSceneAnimated(CC.getCurrentScene().getName())) {
            pauseAnimation();
            startButton.setIcon(new ImageIcon(this.getClass().getResource("/JET/Images/start_animation.PNG")));
            return;
        }

        if (CC.isPaused(CC.getCurrentScene().getName())) {
            unpauseAnimation();
            startButton.setIcon(new ImageIcon(this.getClass().getResource("/JET/Images/pause_animation.PNG")));
            return;
        }
        else
        {
            startAnimation();
            startButton.setIcon(new ImageIcon(this.getClass().getResource("/JET/Images/pause_animation.PNG")));
            return;
        }
}//GEN-LAST:event_startButtonActionPerformed

    private void stopButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_stopButtonActionPerformed
        stopAnimation();
        CC.GUIC.repaintAllSceneTabs();
        updateSceneMenu(CC.getCurrentScene());
        CC.getCurrentScene().GC.clearDrawables();
        
        startButton.setIcon(new ImageIcon(this.getClass().getResource("/JET/Images/start_animation.PNG")));
}//GEN-LAST:event_stopButtonActionPerformed

    private void timestepSliderStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_timestepSliderStateChanged
        double dTime = timestepSlider.getValue() / 100.0;
        CC.getCurrentScene().getJETContext().setDTime(dTime);
        timestepTextField.setText("" + dTime);
}//GEN-LAST:event_timestepSliderStateChanged

    private void timestepTextFieldKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_timestepTextFieldKeyPressed
        if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
            double dTime = timestepSlider.getValue() / 100.0;

            try {
                dTime = Double.parseDouble(timestepTextField.getText());
            } catch (Exception e) {
                // Reset old value
                CC.getCurrentScene().getJETContext().setDTime(dTime);
                timestepTextField.setText("" + dTime);
                timestepSlider.setValue((int) (dTime * 100));

                // Print exception info
                if (debug) System.out.println("textFieldTimeStepKeyPressed -> zły format danych");
                e.printStackTrace();
            }

            // If everything went right - set new time step
            CC.getCurrentScene().getJETContext().setDTime(dTime);
            timestepTextField.setText("" + dTime);
            if (dTime >= 1. / 100.) {
                timestepSlider.setValue((int) (dTime * 100));
            } else {
                timestepSlider.setValue(1);
                CC.getCurrentScene().getJETContext().setDTime(dTime);
                timestepTextField.setText("" + dTime);
            }

        }
    }//GEN-LAST:event_timestepTextFieldKeyPressed

    private void gravityToggleButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_gravityToggleButtonActionPerformed
        Scene scene = CC.getCurrentScene();
        if (scene!=null) {
            scene.getJETContext().setApplyGravity(gravityToggleButton.isSelected());
            Animator animator = CC.getSceneAnimator(scene.getName());
            if (animator!=null)
                animator.context.setApplyGravity(gravityToggleButton.isSelected());
            if (debug) System.out.println("action performed ag= " + CC.getCurrentScene().getJETContext().isApplyGravity());

        }
    }//GEN-LAST:event_gravityToggleButtonActionPerformed

    private void dampingToggleButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_dampingToggleButtonActionPerformed
        Scene scene = CC.getCurrentScene();
        if (scene!=null) {
            scene.getJETContext().setApplyDamping(dampingToggleButton.isSelected());
            Animator animator = CC.getSceneAnimator(scene.getName());
            if (animator!=null)
                animator.context.setApplyDamping(dampingToggleButton.isSelected());
            CC.GUIC.repaintAllSceneTabs();
        }
    }//GEN-LAST:event_dampingToggleButtonActionPerformed

    private void mainGridToggleButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mainGridToggleButtonActionPerformed
        if (CC != null && CC.getCurrentScene().GC.getGraphicPanel() != null) {
            CC.getCurrentScene().GC.setDrawMainGrid(!CC.getCurrentScene().GC.isDrawMainGrid());
            CC.GUIC.repaintAllSceneTabs();
            if (debug) System.out.println("main grid draw = " + CC.getCurrentScene().GC.isDrawMainGrid());
        }
    }//GEN-LAST:event_mainGridToggleButtonActionPerformed

    private void helpGridToggleButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_helpGridToggleButtonActionPerformed
        if (CC != null && CC.getCurrentScene().GC.getGraphicPanel() != null) {
            CC.getCurrentScene().GC.setDrawHelpGrid(!CC.getCurrentScene().GC.isDrawHelpGrid());
            CC.GUIC.repaintAllSceneTabs();
            if (debug) System.out.println("help grid draw = " + CC.getCurrentScene().GC.isDrawHelpGrid());
        }
    }//GEN-LAST:event_helpGridToggleButtonActionPerformed

    private void findCollisionsToggleButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_findCollisionsToggleButtonActionPerformed
        Scene scene = CC.getCurrentScene();
        if (scene!=null) {
            scene.getJETContext().setFindCollisions(findCollisionsToggleButton.isSelected());
            Animator animator = CC.getSceneAnimator(scene.getName());
            if (animator!=null)
                animator.context.setFindCollisions( findCollisionsToggleButton.isSelected());
            CC.GUIC.repaintAllSceneTabs();
        }
    }//GEN-LAST:event_findCollisionsToggleButtonActionPerformed

    private void solveCollisionsToggleButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_solveCollisionsToggleButtonActionPerformed
        Scene scene = CC.getCurrentScene();
        if (scene!=null) {
            scene.getJETContext().setResolveCollisions(solveCollisionsToggleButton.isSelected());
            Animator animator = CC.getSceneAnimator(scene.getName());
            if (animator!=null)
                animator.context.setResolveCollisions( solveCollisionsToggleButton.isSelected());
            CC.GUIC.repaintAllSceneTabs();
        }
    }//GEN-LAST:event_solveCollisionsToggleButtonActionPerformed

    private void drawVelocitiesToggleButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_drawVelocitiesToggleButtonActionPerformed
        if (CC.getCurrentScene()!=null) {
            CC.getCurrentScene().GC.setDrawMass2dVelocities(drawVelocitiesToggleButton.isSelected());
            CC.GUIC.repaintAllSceneTabs();
        }
}//GEN-LAST:event_drawVelocitiesToggleButtonActionPerformed

    private void drawForcesToggleButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_drawForcesToggleButtonActionPerformed
        SA_Menu.setDrawMassForces(drawForcesToggleButton.isSelected(),CC.getCurrentScene(), CC);
}//GEN-LAST:event_drawForcesToggleButtonActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        clearScene();
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        SA_Menu.zeroVelocities(CC.getCurrentScene());
    }//GEN-LAST:event_jButton2ActionPerformed

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        SA_Menu.randomVelocities(CC.getCurrentScene());
    }//GEN-LAST:event_jButton3ActionPerformed

    private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton6ActionPerformed
        SA_SpringBody.addSpringBodyToScene(CC.getCurrentScene(), true);
    }//GEN-LAST:event_jButton6ActionPerformed

    private void jButton7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton7ActionPerformed
        boolean removed = false;
        
        UPSceneInspector upSceneInspector = (UPSceneInspector) CC.GUIC.getUtilTab(UtilTabs.SceneInspector);
        ArrayList<Object> list = TreeUtil.getSelectedInstancesOfClass(upSceneInspector.getSceneTree(), SpringBody.class);
        for (Object o : list) {
            SpringBody sb = (SpringBody) o;
            SA_SpringBody.removeSpringBody(sb, CC.getCurrentScene());
            removed = true;
        }

        if (list.isEmpty()) {
            if (CC.getCurrentScene().EC.currentBody instanceof SpringBody) {
                SA_SpringBody.removeSpringBody((SpringBody)CC.getCurrentScene().EC.currentBody, CC.getCurrentScene());
                removed = true;
            } else if (CC.getCurrentScene().EC.currentBody instanceof RigidBody) {
                // TODO: code for removing rigid bodies...
            }
        }

        if (removed)
            DataModelsFactory.getSceneTreeModel().fireSpringBodyListChanged();
        
        CC.GUIC.repaintAllSceneTabs();
    }//GEN-LAST:event_jButton7ActionPerformed

    private void jMenu3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenu3ActionPerformed
    }//GEN-LAST:event_jMenu3ActionPerformed

    private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1ActionPerformed
        DisplayDialog dd = new DisplayDialog(this, false);
        dd.setLocationRelativeTo(this);
        dd.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
        dd.pack();
        dd.setVisible(true);
    }//GEN-LAST:event_jMenuItem1ActionPerformed

    private void jMenuItem3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem3ActionPerformed
        openProject();
    }//GEN-LAST:event_jMenuItem3ActionPerformed

    private void jMenuItem4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem4ActionPerformed
        saveProjectAs2();
    }//GEN-LAST:event_jMenuItem4ActionPerformed

    private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem2ActionPerformed
        saveProject2();
    }//GEN-LAST:event_jMenuItem2ActionPerformed

    private void jMenuItem5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem5ActionPerformed
        CC.closeCurrentProject();
    }//GEN-LAST:event_jMenuItem5ActionPerformed

    private void menuItemTransformScaleActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuItemTransformScaleActionPerformed
        SA_Selection.clearSelection(CC.getCurrentScene());
        if (CC.getCurrentScene().EC.currentBody instanceof SpringBody) {
            SA_Selection.addSpringBodyToSelection((SpringBody)CC.getCurrentScene().EC.currentBody, CC.getCurrentScene(), false);
        } else if (CC.getCurrentScene().EC.currentBody instanceof RigidBody) {
            // TODO: ...
        }

        CC.MC.setMouseMode(MouseMode.SCALE);
        CC.MC.setMouseSubMode(MouseSubMode.FIND_FIRST_OBJECT);
        CC.GUIC.repaintAllSceneTabs();
    }//GEN-LAST:event_menuItemTransformScaleActionPerformed

    private void menuItemTransformMoveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuItemTransformMoveActionPerformed
        SA_Selection.clearSelection(CC.getCurrentScene());
        //Actions.addSpringBodyToSelection(scene.EC.actualSpringBody);

        CC.MC.setMouseMode(MouseMode.MOVE_MASSES);
        CC.MC.setMouseSubMode(MouseSubMode.FIND_FIRST_OBJECT);
        CC.GUIC.repaintAllSceneTabs();
    }//GEN-LAST:event_menuItemTransformMoveActionPerformed

    private void menuItemTransformRotateActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuItemTransformRotateActionPerformed
        SA_Selection.clearSelection(CC.getCurrentScene());
        if (CC.getCurrentScene().EC.currentBody instanceof SpringBody) {
            SA_Selection.addSpringBodyToSelection((SpringBody)CC.getCurrentScene().EC.currentBody, CC.getCurrentScene(), false);
        } else if (CC.getCurrentScene().EC.currentBody instanceof RigidBody) {}

        CC.MC.setMouseMode(MouseMode.ROTATE);
        CC.MC.setMouseSubMode(MouseSubMode.FIND_FIRST_OBJECT);
        CC.GUIC.repaintAllSceneTabs();
    }//GEN-LAST:event_menuItemTransformRotateActionPerformed

    private void menuItemTranformFlipXActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuItemTranformFlipXActionPerformed
        if (CC.getCurrentScene().EC.currentBody instanceof SpringBody) {
            SA_SpringBody.flipSpringBodyHorizontally((SpringBody) CC.getCurrentScene().EC.currentBody);
        } else if (CC.getCurrentScene().EC.currentBody instanceof RigidBody) {}
        CC.GUIC.repaintAllSceneTabs();
    }//GEN-LAST:event_menuItemTranformFlipXActionPerformed

    private void menuItemTransformFlipYActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuItemTransformFlipYActionPerformed
        if (CC.getCurrentScene().EC.currentBody instanceof SpringBody) {
            SA_SpringBody.flipSpringBodyVertically((SpringBody) CC.getCurrentScene().EC.currentBody);
        } else if (CC.getCurrentScene().EC.currentBody instanceof RigidBody) {}
        CC.GUIC.repaintAllSceneTabs();
    }//GEN-LAST:event_menuItemTransformFlipYActionPerformed

    private void menuItemTransformRotate30ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuItemTransformRotate30ActionPerformed
        if (CC.getCurrentScene().EC.currentBody instanceof SpringBody) {
            SA_SpringBody.rotateSpringBodyByAngle((SpringBody) CC.getCurrentScene().EC.currentBody, Math.toRadians(30.));
        } else if (CC.getCurrentScene().EC.currentBody instanceof RigidBody) {}
        CC.GUIC.repaintAllSceneTabs();
    }//GEN-LAST:event_menuItemTransformRotate30ActionPerformed

    private void menuItemTransformRotate45ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuItemTransformRotate45ActionPerformed
        if (CC.getCurrentScene().EC.currentBody instanceof SpringBody) {
            SA_SpringBody.rotateSpringBodyByAngle((SpringBody) CC.getCurrentScene().EC.currentBody, Math.toRadians(45.));
        } else if (CC.getCurrentScene().EC.currentBody instanceof RigidBody) {}
        CC.GUIC.repaintAllSceneTabs();
}//GEN-LAST:event_menuItemTransformRotate45ActionPerformed

    private void menuItemTransformRotate90ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuItemTransformRotate90ActionPerformed
        if (CC.getCurrentScene().EC.currentBody instanceof SpringBody) {
            SA_SpringBody.rotateSpringBodyByAngle((SpringBody) CC.getCurrentScene().EC.currentBody, Math.toRadians(90.));
        } else if (CC.getCurrentScene().EC.currentBody instanceof RigidBody) {}
        CC.GUIC.repaintAllSceneTabs();
    }//GEN-LAST:event_menuItemTransformRotate90ActionPerformed

    private void menuItemTransformRotate180ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuItemTransformRotate180ActionPerformed
        if (CC.getCurrentScene().EC.currentBody instanceof SpringBody) {
            SA_SpringBody.rotateSpringBodyByAngle((SpringBody) CC.getCurrentScene().EC.currentBody, Math.toRadians(180.));
        } else if (CC.getCurrentScene().EC.currentBody instanceof RigidBody) {}
        CC.GUIC.repaintAllSceneTabs();
    }//GEN-LAST:event_menuItemTransformRotate180ActionPerformed

    private void menuItemCopyActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuItemCopyActionPerformed
        SA_Selection.clearSelection(CC.getCurrentScene());
        if (CC.getCurrentScene().EC.currentBody instanceof SpringBody) {
            SA_Selection.addSpringBodyToSelection((SpringBody) CC.getCurrentScene().EC.currentBody, CC.getCurrentScene(), false);
        } else if (CC.getCurrentScene().EC.currentBody instanceof RigidBody) {}
        CC.MC.setMouseMode(MouseMode.COPY_SELECTED_ITEMS);
        CC.MC.setMouseSubMode(MouseSubMode.FIND_FIRST_OBJECT);
        CC.GUIC.repaintAllSceneTabs();
    }//GEN-LAST:event_menuItemCopyActionPerformed

    private void menuItemSelectAllActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuItemSelectAllActionPerformed
        if ( (evt.getModifiers()&ActionEvent.CTRL_MASK) != ActionEvent.CTRL_MASK )
            SA_Selection.clearSelection(CC.getCurrentScene());

        if (CC.getCurrentScene().EC.currentBody instanceof SpringBody) {
            SA_Selection.addSpringBodyToSelection((SpringBody) CC.getCurrentScene().EC.currentBody, CC.getCurrentScene(), true);
            SA_Dialogs.fillPropertiesDialogWithMassData(CC.getCurrentScene());
            SA_Dialogs.fillPropertiesDialogWithSpringData(CC.getCurrentScene());
        }

        CC.MC.setMouseMode(MouseMode.DO_NOTHING);
        CC.GUIC.repaintAllSceneTabs();
    }//GEN-LAST:event_menuItemSelectAllActionPerformed

    private void menuItemSelectMassesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuItemSelectMassesActionPerformed
        if ( (evt.getModifiers()&ActionEvent.CTRL_MASK) != ActionEvent.CTRL_MASK )
            SA_Selection.clearSelection(CC.getCurrentScene());

        if (CC.getCurrentScene().EC.currentBody instanceof SpringBody) {
            Collection<Mass> massCol = ((SpringBody)CC.getCurrentScene().EC.currentBody).getMassListSync();
            synchronized(massCol) {
                for(Mass mass : massCol)
                    SA_Selection.addMassToSelection(mass, CC.getCurrentScene(), true);
            }

            SA_Dialogs.fillPropertiesDialogWithMassData(CC.getCurrentScene());
        }

        CC.MC.setMouseMode(MouseMode.DO_NOTHING);
        CC.GUIC.repaintAllSceneTabs();
    }//GEN-LAST:event_menuItemSelectMassesActionPerformed

    private void menuItemSelectSpringsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuItemSelectSpringsActionPerformed
        if ( (evt.getModifiers()&ActionEvent.CTRL_MASK) != ActionEvent.CTRL_MASK )
            SA_Selection.clearSelection(CC.getCurrentScene());

        if (CC.getCurrentScene().EC.currentBody instanceof SpringBody) {
            for(Spring spring : ((SpringBody)CC.getCurrentScene().EC.currentBody).getSpringList())
                SA_Selection.addSpringToSelection(spring, CC.getCurrentScene(), true);
            SA_Dialogs.fillPropertiesDialogWithSpringData(CC.getCurrentScene());
        }

        CC.MC.setMouseMode(MouseMode.DO_NOTHING);
        CC.GUIC.repaintAllSceneTabs();
    }//GEN-LAST:event_menuItemSelectSpringsActionPerformed

    private void menuItemSelectWallsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuItemSelectWallsActionPerformed
        if ( (evt.getModifiers()&ActionEvent.CTRL_MASK) != ActionEvent.CTRL_MASK )
            SA_Selection.clearSelection(CC.getCurrentScene());

        if (CC.getCurrentScene().EC.currentBody instanceof SpringBody) {
            for(Wall wall : ((SpringBody)CC.getCurrentScene().EC.currentBody).getBorder().getWallList())
                SA_Selection.addWallToSelection(wall, CC.getCurrentScene(), true);
        }
        CC.MC.setMouseMode(MouseMode.DO_NOTHING);
        CC.GUIC.repaintAllSceneTabs();
    }//GEN-LAST:event_menuItemSelectWallsActionPerformed

    private void menuItemSpringsRecalculateStartLengthActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuItemSpringsRecalculateStartLengthActionPerformed
        if (CC.getCurrentScene().EC.currentBody instanceof SpringBody) {
            for(Spring spring : ((SpringBody)CC.getCurrentScene().EC.currentBody).getSpringList())
                spring.setStartLength( spring.getVector().getMagnitude() );
        }
    }//GEN-LAST:event_menuItemSpringsRecalculateStartLengthActionPerformed

    private void menuItemMassesSetMassValueActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuItemMassesSetMassValueActionPerformed
        SA_Selection.clearSelection(CC.getCurrentScene());

        if (CC.getCurrentScene().EC.currentBody instanceof SpringBody) {
            Collection<Mass> massCol = ((SpringBody)CC.getCurrentScene().EC.currentBody).getMassListSync();
            synchronized(massCol) {
                for(Mass mass : massCol)
                    SA_Selection.addMassToSelection(mass, CC.getCurrentScene(), true);
            }

            SA_Dialogs.fillPropertiesDialogWithMassData(CC.getCurrentScene());
            CC.MC.setMouseMode(MouseMode.DO_NOTHING);
            CC.GUIC.repaintAllSceneTabs();
            UPMass upMass = (UPMass) CC.GUIC.getUtilTab(UtilTabs.Mass);
            upMass.bringFocusToMassTextField();
        }
    }//GEN-LAST:event_menuItemMassesSetMassValueActionPerformed

    private void menuItemSpringsSetKsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuItemSpringsSetKsActionPerformed
        SA_Selection.clearSelection(CC.getCurrentScene());

        if (CC.getCurrentScene().EC.currentBody instanceof SpringBody) {
            for(Spring spring : ((SpringBody)CC.getCurrentScene().EC.currentBody).getSpringList())
                SA_Selection.addSpringToSelection(spring, CC.getCurrentScene(), true);
            SA_Dialogs.fillPropertiesDialogWithSpringData(CC.getCurrentScene());
            CC.MC.setMouseMode(MouseMode.DO_NOTHING);
            CC.GUIC.repaintAllSceneTabs();
            UPSpring upSpring = (UPSpring) CC.GUIC.getUtilTab(UtilTabs.Spring);
            upSpring.bringFocusToSpringsKsTextField();
        }
    }//GEN-LAST:event_menuItemSpringsSetKsActionPerformed

    private void menuItemSpringsSetKdActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuItemSpringsSetKdActionPerformed
        SA_Selection.clearSelection(CC.getCurrentScene());
        if (CC.getCurrentScene().EC.currentBody instanceof SpringBody) {
            for(Spring spring : ((SpringBody)CC.getCurrentScene().EC.currentBody).getSpringList())
                SA_Selection.addSpringToSelection(spring, CC.getCurrentScene(), true);
            SA_Dialogs.fillPropertiesDialogWithSpringData(CC.getCurrentScene());
            CC.MC.setMouseMode(MouseMode.DO_NOTHING);
            CC.GUIC.repaintAllSceneTabs();
            UPSpring upSpring = (UPSpring) CC.GUIC.getUtilTab(UtilTabs.Spring);
            upSpring.bringFocusToSpringsKdTextField();
        }
    }//GEN-LAST:event_menuItemSpringsSetKdActionPerformed

    private void menuItemSpringsSetStartLengthActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuItemSpringsSetStartLengthActionPerformed
        SA_Selection.clearSelection(CC.getCurrentScene());
        if (CC.getCurrentScene().EC.currentBody instanceof SpringBody) {
            for(Spring spring : ((SpringBody)CC.getCurrentScene().EC.currentBody).getSpringList())
                SA_Selection.addSpringToSelection(spring, CC.getCurrentScene(), true);
            SA_Dialogs.fillPropertiesDialogWithSpringData(CC.getCurrentScene());
            CC.MC.setMouseMode(MouseMode.DO_NOTHING);
            CC.GUIC.repaintAllSceneTabs();
            UPSpring upSpring = (UPSpring) CC.GUIC.getUtilTab(UtilTabs.Spring);
            upSpring.bringFocusToStartLengthTextField();
        }
    }//GEN-LAST:event_menuItemSpringsSetStartLengthActionPerformed

    private void menuItemMassesSetVelocityActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuItemMassesSetVelocityActionPerformed
        SA_Selection.clearSelection(CC.getCurrentScene());
        if (CC.getCurrentScene().EC.currentBody instanceof SpringBody) {
            Collection<Mass> massCol = ((SpringBody)CC.getCurrentScene().EC.currentBody).getMassListSync();
            synchronized(massCol) {
                for(Mass mass : massCol)
                    SA_Selection.addMassToSelection(mass, CC.getCurrentScene(), true);
            }

            SA_Dialogs.fillPropertiesDialogWithMassData(CC.getCurrentScene());
            CC.MC.setMouseMode(MouseMode.DO_NOTHING);
            CC.GUIC.repaintAllSceneTabs();
            UPMass upMass = (UPMass) CC.GUIC.getUtilTab(UtilTabs.Mass);
            upMass.bringFocusToVelocityPanel();
        }
    }//GEN-LAST:event_menuItemMassesSetVelocityActionPerformed

    private void newProjectButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_newProjectButtonActionPerformed
        CC.closeCurrentProject();
}//GEN-LAST:event_newProjectButtonActionPerformed

    private void openProjectButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_openProjectButtonActionPerformed
        openProject();
}//GEN-LAST:event_openProjectButtonActionPerformed

    private void saveProjectButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveProjectButtonActionPerformed
        saveProject2();
}//GEN-LAST:event_saveProjectButtonActionPerformed

    private void refreshButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_refreshButtonActionPerformed
        refreshProject();
}//GEN-LAST:event_refreshButtonActionPerformed

    private void showMaterialsDialogCheckBoxMenuItemItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_showMaterialsDialogCheckBoxMenuItemItemStateChanged
        SA_Dialogs.setVisibleMaterialsDialog( showMaterialsDialogCheckBoxMenuItem.isSelected() );
    }//GEN-LAST:event_showMaterialsDialogCheckBoxMenuItemItemStateChanged

    private void followCameraToggleButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_followCameraToggleButtonActionPerformed
        CC.getCurrentScene().EC.setFollowCamera( followCameraToggleButton.isSelected() );
        CC.GUIC.repaintAllSceneTabs();
    }//GEN-LAST:event_followCameraToggleButtonActionPerformed

    private void actionFrameToggleButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_actionFrameToggleButtonActionPerformed
        CC.getCurrentScene().GC.setDrawActionFrame(actionFrameToggleButton.isSelected());
        CC.GUIC.repaintAllSceneTabs();
    }//GEN-LAST:event_actionFrameToggleButtonActionPerformed

    private void showActionsDialogCheckBoxMenuItemItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_showActionsDialogCheckBoxMenuItemItemStateChanged
        SA_Dialogs.setVisibleActionsDialog( showActionsDialogCheckBoxMenuItem.isSelected() );
    }//GEN-LAST:event_showActionsDialogCheckBoxMenuItemItemStateChanged

    private void showKeyboardDialogCheckBoxMenuItemItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_showKeyboardDialogCheckBoxMenuItemItemStateChanged
        SA_Dialogs.setVisibleKeyboardDialog( showKeyboardDialogCheckBoxMenuItem.isSelected() );
    }//GEN-LAST:event_showKeyboardDialogCheckBoxMenuItemItemStateChanged

    private void gravityTextFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_gravityTextFieldActionPerformed
        double g = Double.parseDouble(gravityTextField.getText());
        Scene s = CC.getCurrentScene();
        if (s!=null) {
            s.getJETContext().gravity = g;
            gravityTextField.setText(""+g);
        } else
            gravityTextField.setText("");
    }//GEN-LAST:event_gravityTextFieldActionPerformed

    private void jMenuItem6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem6ActionPerformed
        AdvancedSimulationSettingsDialog assd = new AdvancedSimulationSettingsDialog(this, false);
        assd.setLocationRelativeTo(null);
        assd.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
        assd.pack();
        assd.setVisible(true);
    }//GEN-LAST:event_jMenuItem6ActionPerformed

    private void showRecorderDialogCheckBoxMenuItemItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_showRecorderDialogCheckBoxMenuItemItemStateChanged
       SA_Dialogs.setVisibleRecorderDialog(showRecorderDialogCheckBoxMenuItem.isSelected());
    }//GEN-LAST:event_showRecorderDialogCheckBoxMenuItemItemStateChanged

    private void recordButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_recordButtonActionPerformed
        CC.setRecord(recordButton.isSelected());
    }//GEN-LAST:event_recordButtonActionPerformed

    private void jButton8ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton8ActionPerformed
        try {
            Transformer t = TransformerFactory.newInstance().newTransformer();
            FileOutputStream foStream = new FileOutputStream("XMLHelper2_test.xml");
            t.transform(new DOMSource(XMLHelper2.buildProjectElement()), new StreamResult(foStream));
            foStream.close();
        } catch (Exception ex) {
            Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_jButton8ActionPerformed

    private void jMenuItem7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem7ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jMenuItem7ActionPerformed

    private void jMenuItem8ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem8ActionPerformed
        AboutDialog ad = new AboutDialog(this, true);
        ad.setLocationRelativeTo(null);
        ad.setVisible(true);
    }//GEN-LAST:event_jMenuItem8ActionPerformed

    private void glToggleButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_glToggleButtonActionPerformed
        try {
            Scene scene = CC.getCurrentScene();
            switch (scene.GC.getGraphicMode()) {
                case Swing :
                    scene.GC.setGraphicMode(GraphicMode.OpenGL);
                    break;
                case OpenGL :
                    scene.GC.setGraphicMode(GraphicMode.Swing);
                    break;
            }
        } catch(JETGraphicsException e) {
            JOptionPane.showMessageDialog(this, e.getMessage(), "Graphics error", JOptionPane.ERROR_MESSAGE);
        }
    }//GEN-LAST:event_glToggleButtonActionPerformed

    private void jButton9ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton9ActionPerformed
        Scene scene = CC.getCurrentScene();
        ArrayList<Object> list = null;

        list = BodyFactory.buildSquareNet(
                            CC, false, 1,
                            new Vec2d(0,50),
                            new Vec2d(50,0),
                            1.0,
                            START_MASS_BOUNCE_FACTOR,
                            START_MASS_FRICTION_FACTOR);

        if (list != null) {
            if ( CC.createNewSpringBody ) SA_SpringBody.addSpringBodyToScene(scene, true);
            scene.getJETContext().getSpringBodyList().get(0).setName("textured");
            
            if ( scene.EC.currentBody != null) {
                SA_Mass.addMassListToSpringBody((ArrayList<Mass>) list.get(0), (SpringBody)scene.EC.currentBody, false);
                SA_Wall.addWallListToSpringBody((ArrayList<Wall>) list.get(1), (SpringBody)scene.EC.currentBody, false);
                SA_Spring.addSpringListToSpringBody((ArrayList<Spring>) list.get(2), (SpringBody)scene.EC.currentBody, false);
                scene.EC.currentBody.getBorder().checkIfBorderIsProper();

                DataModelsFactory.getSceneTreeModel().fireSpringBodyChanged((SpringBody)scene.EC.currentBody);
            }
        }
    }//GEN-LAST:event_jButton9ActionPerformed

    private void jMenuItem3ActionPerformed1(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem3ActionPerformed1
        openProject();
    }//GEN-LAST:event_jMenuItem3ActionPerformed1

    private void saveGuiLayoutMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveGuiLayoutMenuItemActionPerformed
        saveGuiLayout();
    }//GEN-LAST:event_saveGuiLayoutMenuItemActionPerformed

    private void menuItemGroupAsSceneItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuItemGroupAsSceneItemActionPerformed
        Scene scene = CC.getCurrentScene();
        if (scene!=null)
        {
            SceneItem sItem = SA_SceneItems.buildSceneItemFromSelectionGroup(scene.EC.selectionGroup);
            scene.addSceneItem(sItem);

            DataModelsFactory.getSceneTreeModel().fireWholeTreeChanged();
            DataModelsFactory.getSceneItemsTreeModel().fireWholeTreeChanged();
        }
    }//GEN-LAST:event_menuItemGroupAsSceneItemActionPerformed

    private void menuItemSpreadSelectionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuItemSpreadSelectionActionPerformed
        Scene scene = CC.getCurrentScene();
        if (scene!=null)
        {
            scene.EC.selectionGroup.spreadSelection(true, true, true);
        }
    }//GEN-LAST:event_menuItemSpreadSelectionActionPerformed

    private void resetGuiLayoutMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_resetGuiLayoutMenuItemActionPerformed
        MultiSplitPane msp=null;
        File layoutFile = new File("guiLayout.xml");
        FileInputStream is=null;
        if (layoutFile.exists())
            try {
                msp = CC.GUIC.builGuiSctructure((is= new FileInputStream(layoutFile)), CC);
            } catch(Exception ex) {ex.printStackTrace();}
            finally {
                try {if (is!=null)is.close();}catch(Exception e) {e.printStackTrace();}
            }
        else
            msp = CC.GUIC.builGuiSctructure(Object.class.getResourceAsStream("/JET/gui.xml"), CC);

        if (msp==null) throw new RuntimeException("main(), msp is null !");
        guiRootPanel.remove(guiRootPanel.getComponent(0));
        guiRootPanel.add(msp, BorderLayout.CENTER);
        guiRootPanel.updateUI();
    }//GEN-LAST:event_resetGuiLayoutMenuItemActionPerformed

//    private void saveProjectAs()
//    {
//        JFileChooser fc;
//
//        if (CC.getCurrentDirectory() != null)
//            fc = new JFileChooser(CC.getCurrentDirectory());
//        else
//            fc = new JFileChooser();
//
//        fc.setFileFilter( new XMLFileFilter());
//
//        int returnVal = fc.showSaveDialog(this);
//
//        if (returnVal == JFileChooser.APPROVE_OPTION) {
//            File file = fc.getSelectedFile();
//            CC.setCurrentDirectory( fc.getCurrentDirectory() );
//
//            if (file.exists())
//            {
//                int yesno = JOptionPane.showConfirmDialog(this,
//                                              "Selected file already exists,\n do you want to overwrite it?",
//                                               "alert", JOptionPane.YES_NO_OPTION);
//                if (yesno == JOptionPane.OK_OPTION)
//                    CC.setProjectFile(file.getPath());
//            }
//            else
//            {
//                String filename = file.getName();
//                String ext = Utils.getFileExtension(filename);
//                if ( ext.equals("") )
//                {
//                    CC.setProjectFile(file.getPath()+".xml");
//                }
//                else if ( !ext.equals("xml") )
//                {
//                    String newPath = Utils.switchFileExtensionTo(file.getPath(), "xml");
//                    System.out.println("Switched file ext, and now path is "+newPath);
//                    CC.setProjectFile( newPath );
//                }
//            }
//            try {
//                CC.saveProjectFile(CC.getProjectFile());
//            } catch (ParserConfigurationException ex) {
//                Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
//            } catch (TransformerConfigurationException ex) {
//                Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
//            } catch (TransformerException ex) {
//                Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
//            } catch (FileNotFoundException ex) {
//                Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
//            } catch (IOException ex) {
//                Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
//            }
//        }
//    }
    
//    private void saveProject()
//    {
//        if (CC.getProjectFile().equals(""))
//        {
//            saveProjectAs();
//            setRefreshButtonEnabled(true);
//        }
//        else
//            try {
//            CC.saveProjectFile(CC.getProjectFile());
//            setRefreshButtonEnabled(true);
//        } catch (ParserConfigurationException ex) {
//            Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
//        } catch (TransformerConfigurationException ex) {
//            Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
//        } catch (TransformerException ex) {
//            Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
//        } catch (FileNotFoundException ex) {
//            Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
//        } catch (IOException ex) {
//            Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
//        }
//    }

    private void saveProjectAs2() {
        JFileChooser fc;

        if (CC.getCurrentDirectory() != null)
            fc = new JFileChooser(CC.getCurrentDirectory());
        else
            fc = new JFileChooser();

        fc.setFileFilter( new XMLFileFilter());

        CC.pauseAll();
        int returnVal = fc.showSaveDialog(this);

        if (returnVal == JFileChooser.APPROVE_OPTION) {
            File file = fc.getSelectedFile();
            CC.setCurrentDirectory( fc.getCurrentDirectory() );

            if (file.exists())
            {
                int yesno = JOptionPane.showConfirmDialog(this,
                                              "Selected file already exists,\n do you want to overwrite it?",
                                               "alert", JOptionPane.YES_NO_OPTION);
                if (yesno == JOptionPane.OK_OPTION)
                    CC.setProjectFile(file.getPath());
            }
            else
            {
                String filename = file.getName();
                String ext = Utils.getFileExtension(filename);
                if ( ext.equals("") )
                {
                    CC.setProjectFile(file.getPath()+".xml");
                }
                else if ( !ext.equals("xml") )
                {
                    String newPath = Utils.switchFileExtensionTo(file.getPath(), "xml");
                    System.out.println("Switched file ext, and now path is "+newPath);
                    CC.setProjectFile( newPath );
                }
            }

            CC.saveProjectFile2(CC.getProjectFile());
        }
        
        ControlCenterHelper.clearAllScenesCache();
        CC.unpauseAll(false);
    }

    private void saveProject2() {
        if (CC.getProjectFile().equals("")) {
            saveProjectAs2();
            setRefreshButtonEnabled(true);
        }
        else {
            CC.pauseAll();
            CC.saveProjectFile2(CC.getProjectFile());
            ControlCenterHelper.clearAllScenesCache();
            CC.unpauseAll(false);
        }
    }

    private void openProject()
    {
        JFileChooser fc;
        if (CC.getCurrentDirectory() != null)
            fc = new JFileChooser(CC.getCurrentDirectory());
        else
            fc = new JFileChooser();

        fc.setFileFilter( new XMLFileFilter());
        
        int returnVal = fc.showOpenDialog(this);

        if (returnVal == JFileChooser.APPROVE_OPTION) {
            File file = fc.getSelectedFile();
            CC.setCurrentDirectory( fc.getCurrentDirectory() );

            try {
                CC.closeCurrentProject();

                //CC.loadProjectFile(file.getPath(), true);
                CC.loadProjectFile2(file.getPath());
                CC.setProjectFile(file.getPath());
                this.refreshButton.setEnabled(true);
            
            } catch (Exception ex) {
                JOptionPane.showMessageDialog(this,
                "Ex: "+ex,
                "Cannot load project",
                JOptionPane.ERROR_MESSAGE);
            }

        } else {
            // Nie ce mi sie otwierac ... ;]
        }
    }

    private void refreshProject()
    {
        try {
            String lastProjectFile = CC.getProjectFile();
            CC.closeCurrentProject();
            CC.loadProjectFile2(lastProjectFile);
            CC.setProjectFile(lastProjectFile);
        } catch (Exception ex) {ex.printStackTrace();}
    }

    public void setStartButtonEnabled(boolean b) {
        startButton.setEnabled(b);
    }
    public void setStopButtonEnabled(boolean b) {
        stopButton.setEnabled(b);
    }

    public void updateSceneMenu(Scene s) {
        if (CC.isSceneAnimated(s.getName()))
            startButton.setIcon(new ImageIcon(this.getClass().getResource("/JET/Images/pause_animation.PNG")));
        else
            startButton.setIcon(new ImageIcon(this.getClass().getResource("/JET/Images/start_animation.PNG")));

        timestepSlider.setValue((int) (s.getJETContext().getDTime() * 100));
        timestepTextField.setText(""+s.getJETContext().getDTime());

        gravityToggleButton.setSelected(s.getJETContext().isApplyGravity());
        gravityTextField.setText(""+s.getJETContext().gravity);

        dampingToggleButton.setSelected(s.getJETContext().isApplyDamping());
        drawForcesToggleButton.setSelected(s.GC.isDrawMass2dForces());
        drawVelocitiesToggleButton.setSelected(s.GC.isDrawMass2dVelocities());
        followCameraToggleButton.setSelected(s.EC.followCamera);
        glToggleButton.setSelected(s.GC.getGraphicMode()==GraphicMode.OpenGL ? true:false);
        mainGridToggleButton.setSelected(s.GC.isDrawMainGrid());
        helpGridToggleButton.setSelected(s.GC.isDrawHelpGrid());
        findCollisionsToggleButton.setSelected(s.getJETContext().isFindCollisions());
        solveCollisionsToggleButton.setSelected(s.getJETContext().isResolveCollisions());
    }

    public void startAnimation() {
        if (debug) System.out.println("MainFrame.startAnimation()");
        CC.getCurrentScene().SC.initJSEngine();
        CC.GUIC.saveAllScripts();
        CC.getCurrentScene().SC.compileAll();
        CC.getCurrentScene().SC.executeAll();

        CC.getCurrentScene().cache();

        CC.play(CC.GUIC.getCurrentSceneName());
    }

    public void stopAnimation() {
        if (debug) System.out.println("MainFrame.stopAnimation()");
        CC.stop(CC.GUIC.getCurrentSceneName());


        CC.getCurrentScene().reloadCached();
        CC.GUIC.setCurrentScene(CC.getCurrentScene().getName());
    }

    public void pauseAnimation() {
        if (debug) System.out.println("MainFrame.pauseAnimation()");
        CC.pause(CC.GUIC.getCurrentSceneName());
    }

    public void unpauseAnimation() {
        if (debug) System.out.println("MainFrame.unpauseAnimation()");
        CC.unpause(CC.GUIC.getCurrentSceneName(), true);
    }
    
    public void setFPSCountText(String t) {
        //fpsLabel2.setText( t );
    }

    public void setFPS2CountText(String t) {
        //fpsLabel4.setText( t );
    }

    public void setMouseModeLabel(String t)
    {
        labelMouseMode.setText(t);
    }

    public void setMouseTaskLabel(String t)
    {
        labelMouseTask.setText(t);
    }

    public void setViewScaleLabel(double viewScale) {
        StringBuilder sb = new StringBuilder();
        Formatter formatter = new Formatter(sb, Locale.US);
        formatter.format("%4.2f", viewScale);
        labelViewScale.setText("view scale: " + formatter.toString());
    }

    public void setGPWidthLabel(double width) {
        StringBuilder sb = new StringBuilder();
        Formatter formatter = new Formatter(sb, Locale.US);
        formatter.format("%10.0f", width);
        //jLabel18.setText( formatter.toString() );
    }

    public void setGPHeightLabel(double height) {
        StringBuilder sb = new StringBuilder();
        Formatter formatter = new Formatter(sb, Locale.US);
        formatter.format("%10.0f", height);
        //jLabel19.setText( formatter.toString() );
    }

    public void setMouseScreenPos(MouseEvent evt) {
        labelMouseScreenPos.setText("screen [" + evt.getX() + ", " + evt.getY() + "]");
    }

    public void setMouseEnginePos(MouseEvent evt) {
        StringBuilder sbX = new StringBuilder();
        StringBuilder sbY = new StringBuilder();
        double x,y;
//        if (evt.isShiftDown())
//        {
            Scene scene = CC.getCurrentScene();
            x = scene.EC.engCursor.getX();
            y = scene.EC.engCursor.getY();
//        }
//        else
//        {
//            x = CC.monitorToEngineX(evt.getXOnScreen());
//            y = CC.monitorToEngineY(evt.getYOnScreen());
//        }
        Formatter formatterX = new Formatter(sbX, Locale.US);
        formatterX.format("%6.1f", x);
        Formatter formatterY = new Formatter(sbY, Locale.US);
        formatterY.format("%6.1f", y);
        labelMouseEnginePos.setText("scene [" + formatterX + ", " + formatterY + "]");
    }

    private int getEngineStartDTimeForSlider() {
        int max = timestepSlider.getMaximum();
        int min = timestepSlider.getMinimum();
        int range = max - min;

        return (int) (ENGINE_START_DTIME * range);
    }

    public double getM2DsBounceFactor() {
        return 0.5;
    }

    public double getM2DsFrictioFactor() {
        return 0.3;
    }

    public void clearScene()
    {
        SA_Menu.clearScene(CC.getCurrentScene());
        CC.getCurrentScene().EC.selectionGroup.clear();
        CC.GUIC.repaintAllSceneTabs();
        DataModelsFactory.getSceneTreeModel().fireWholeTreeChanged();
    }

    public JCheckBoxMenuItem getShowMaterialsDialogCheckBoxMenuItem() {
        return showMaterialsDialogCheckBoxMenuItem;
    }

    public JCheckBoxMenuItem getShowActionsDialogCheckBoxMenuItem() {
        return showActionsDialogCheckBoxMenuItem;
    }

    public JCheckBoxMenuItem getShowKeyboardDialogCheckBoxMenuItem() {
        return showKeyboardDialogCheckBoxMenuItem;
    }

    public JCheckBoxMenuItem getShowRecorderDialogCheckBoxMenuItem() {
        return showRecorderDialogCheckBoxMenuItem;
    }

    public void showPopupSpringBody(MouseEvent e) {
        popUpMenuSpringBody.show(e.getComponent(), e.getX(), e.getY());
    }

    public void showPopupScene(MouseEvent e) {
        Scene scene = CC.getCurrentScene();
        if (scene!=null)
        {
            menuSelection.setEnabled(!scene.EC.selectionGroup.isEmpty());
            popUpMenuScene.show(e.getComponent(), e.getX(), e.getY());
        }
    }

    public void setRefreshButtonEnabled(boolean enabled)
    {
        refreshButton.setEnabled(enabled);
    }

    public void setFollowCameraButtonSelected(boolean selected)
    {
        followCameraToggleButton.setSelected(selected);
    }

    public void setDrawActionFrameButtonSelected(boolean selected)
    {
        actionFrameToggleButton.setSelected(selected);
    }

    public void saveGuiLayout() {
        if (debug) System.out.println(MyGuiManager.getInstance().getRootMSP().toString(0));
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        DocumentBuilder db = null;
        try {
            db = dbf.newDocumentBuilder();
        } catch (ParserConfigurationException ex) {ex.printStackTrace();}
        Document doc = db.newDocument();
        doc.appendChild(MyGuiManager.getInstance().getRootMSP().getXMLElement(doc));
        FileOutputStream foStream = null;
        try {
            Transformer t = TransformerFactory.newInstance().newTransformer();
            foStream = new FileOutputStream("guiLayout.xml");
            t.transform(new DOMSource(doc), new StreamResult(foStream));
            foStream.close();
        } catch(Exception e) { e.printStackTrace(); }
        finally {
            try {
                if (foStream != null) foStream.close();
            }  catch (Exception e) { e.printStackTrace(); }
        }
    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JToggleButton actionFrameToggleButton;
    private javax.swing.JToggleButton dampingToggleButton;
    private javax.swing.JToggleButton drawForcesToggleButton;
    private javax.swing.JToggleButton drawVelocitiesToggleButton;
    private javax.swing.JToggleButton findCollisionsToggleButton;
    private javax.swing.JToggleButton followCameraToggleButton;
    private javax.swing.JToggleButton glToggleButton;
    private javax.swing.JTextField gravityTextField;
    private javax.swing.JToggleButton gravityToggleButton;
    public javax.swing.JPanel guiRootPanel;
    private javax.swing.JToggleButton helpGridToggleButton;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton6;
    private javax.swing.JButton jButton7;
    private javax.swing.JButton jButton8;
    private javax.swing.JButton jButton9;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenu jMenu3;
    private javax.swing.JMenu jMenu4;
    private javax.swing.JMenu jMenu5;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JMenuItem jMenuItem2;
    private javax.swing.JMenuItem jMenuItem3;
    private javax.swing.JMenuItem jMenuItem4;
    private javax.swing.JMenuItem jMenuItem5;
    private javax.swing.JMenuItem jMenuItem6;
    private javax.swing.JMenuItem jMenuItem7;
    private javax.swing.JMenuItem jMenuItem8;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JSeparator jSeparator2;
    private javax.swing.JSeparator jSeparator3;
    private javax.swing.JSeparator jSeparator4;
    private javax.swing.JPopupMenu.Separator jSeparator5;
    private javax.swing.JPopupMenu.Separator jSeparator6;
    private javax.swing.JLabel labelMouseEnginePos;
    private javax.swing.JLabel labelMouseMode;
    private javax.swing.JLabel labelMouseScreenPos;
    private javax.swing.JLabel labelMouseTask;
    private javax.swing.JLabel labelViewScale;
    private javax.swing.JToggleButton mainGridToggleButton;
    private javax.swing.JMenuItem menuItemCopy;
    private javax.swing.JMenuItem menuItemGroupAsSceneItem;
    private javax.swing.JMenuItem menuItemMassesSetMassValue;
    private javax.swing.JMenuItem menuItemMassesSetVelocity;
    private javax.swing.JMenuItem menuItemSelectAll;
    private javax.swing.JMenuItem menuItemSelectMasses;
    private javax.swing.JMenuItem menuItemSelectSprings;
    private javax.swing.JMenuItem menuItemSelectWalls;
    private javax.swing.JMenuItem menuItemSpreadSelection;
    private javax.swing.JMenuItem menuItemSpringsRecalculateStartLength;
    private javax.swing.JMenuItem menuItemSpringsSetKd;
    private javax.swing.JMenuItem menuItemSpringsSetKs;
    private javax.swing.JMenuItem menuItemSpringsSetStartLength;
    private javax.swing.JMenuItem menuItemTranformFlipX;
    private javax.swing.JMenuItem menuItemTransformFlipY;
    private javax.swing.JMenuItem menuItemTransformMove;
    private javax.swing.JMenuItem menuItemTransformRotate;
    private javax.swing.JMenuItem menuItemTransformRotate180;
    private javax.swing.JMenuItem menuItemTransformRotate30;
    private javax.swing.JMenuItem menuItemTransformRotate45;
    private javax.swing.JMenuItem menuItemTransformRotate90;
    private javax.swing.JMenuItem menuItemTransformScale;
    private javax.swing.JMenu menuMasses;
    private javax.swing.JMenu menuSelect;
    private javax.swing.JMenu menuSelection;
    private javax.swing.JMenu menuSprings;
    private javax.swing.JMenu menuTransform;
    private javax.swing.JButton newProjectButton;
    private javax.swing.JButton openProjectButton;
    private javax.swing.JPanel panelMouseEnginePos;
    private javax.swing.JPanel panelMouseMode;
    private javax.swing.JPanel panelMouseScreenPos;
    private javax.swing.JPanel panelMouseTask;
    private javax.swing.JPanel panelViewScale;
    private javax.swing.JPopupMenu popUpMenuScene;
    private javax.swing.JPopupMenu popUpMenuSpringBody;
    private javax.swing.JToggleButton recordButton;
    private javax.swing.JButton refreshButton;
    private javax.swing.JMenuItem resetGuiLayoutMenuItem;
    private javax.swing.JMenuItem saveGuiLayoutMenuItem;
    private javax.swing.JButton saveProjectButton;
    private javax.swing.JCheckBoxMenuItem showActionsDialogCheckBoxMenuItem;
    private javax.swing.JCheckBoxMenuItem showKeyboardDialogCheckBoxMenuItem;
    private javax.swing.JCheckBoxMenuItem showMaterialsDialogCheckBoxMenuItem;
    private javax.swing.JCheckBoxMenuItem showRecorderDialogCheckBoxMenuItem;
    private javax.swing.JToggleButton solveCollisionsToggleButton;
    private javax.swing.JButton startButton;
    private javax.swing.JPanel statusBarPanel;
    private javax.swing.JButton stopButton;
    private javax.swing.JSlider timestepSlider;
    private javax.swing.JTextField timestepTextField;
    // End of variables declaration//GEN-END:variables

//    public JPanel getGraphicPanelContainer() {
//        return graphicPanelContainer;
//    }

//    public JPanel getToolOptionsPanel() {
//        return toolOptionsPanel;
//    }

    private class MainFrameComponentListener implements ComponentListener {

        public void componentResized(ComponentEvent evt) {
            /*
            if (CC != null && scene.GC.getGraphicPanel(CC.GUIC.getActualSceneName()) != null) {
                scene.GC.resizeViewToFitViewScale();
            }
            */
        }

        public void componentMoved(ComponentEvent arg0) {
        }

        public void componentShown(ComponentEvent arg0) {
        }

        public void componentHidden(ComponentEvent arg0) {
        }
    }
}
